$(document).ready(function(){
    var clazzId = "";
        $.ajax({
            type : "GET",
            url : "/clazz/getClazz",
            dataType : "json",
            data : {
            },
            success : function(data) {
                console.log(data);
                for(var i in data){
                    if(i==0){
                        $("#selectClazz").append("<option value="+data[i].id+" selected='selected'>"+data[i].name+"</option>");
                    }else{
                        $("#selectClazz").append("<option value="+data[i].id+">"+data[i].name+"</option>");
                    }
                }

                clazzId = $("#selectClazz").val();
                getUser();
                $("#selectClazz").change(function(){
                    clazzId = $("#selectClazz").val();
                    $("#selectStudent").empty();
                    getUser();
                });

            },
            error : function(xhr,textStatus) {
                console.log('错误');
                console.log(xhr);
                console.log(textStatus);
            }
        });


        function getUser(){
            $.ajax({
                type : "GET",
                url : "/clazz/getUsers",
                dataType : "json",
                data : {
                    id:clazzId,
                },
                success : function(data) {
                    console.log(data);
                    for(var i in data){
                        if(i==0){
                            $("#selectStudent").append("<option value="+data[i].id+" selected='selected'>"+data[i].name+"</option>");
                        }else{
                            $("#selectStudent").append("<option value="+data[i].id+">"+data[i].name+"</option>");
                        }
                    }
                },
                error : function(xhr,textStatus) {
                    console.log('错误');
                    console.log(xhr);
                    console.log(textStatus);
                }
            });
        }
});